Pick alignment tool
Description
Remarks
-
This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.
-
If you encounter any error while using DgnElementSetTool class, make sure to add a reference to Bentley.DgnDisplayNet.dll by selecting Project > Add Reference or change the projects.csproj file to add reference to this dll.
-
The dll location will be "C:\Program Files\Bentley\OpenRoads Designer CE 10.11\OpenRoadsDesigner\Bentley.DgnDisplayNet.dll".
Source Code
//Required References
using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.SDK;
namespace ManagedSDKExample
{
class PickAlignmentTool : DgnElementSetTool
{
ConsensusConnection m_con;
public PickAlignmentTool() : base()
{
}
protected override void OnRestartTool()
{
InstallNewInstance();
}
protected override void ExitTool()
{
if (m_con != null)
{
m_con.Close();
m_con.Dispose();
}
m_con = null;
base.ExitTool();
}
protected override void OnPostInstall()
{
base.BeginPickElements();
Bentley.DgnPlatformNET.AccuSnap.LocateEnabled = true;
Bentley.DgnPlatformNET.AccuSnap.SnapEnabled = true;
m_con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
if (m_con == null)
return;
NotificationManager.OutputPrompt("Select an alignment to report.");
base.OnPostInstall();
}
//selects an alignment
protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
{
Bentley.DgnPlatformNET.HitPath hitPath = DoLocate(ev, true, 0);
if (hitPath == null)
return false;
Element el = hitPath.GetCursorElement();
if (el == null)
return false;
Alignment al = (el.ParentElement == null) ? Alignment.CreateFromElement(m_con, el) : Alignment.CreateFromElement(m_con, el.ParentElement);
if (al == null)
return false;
return true;
}
public override Bentley.DgnPlatformNET.StatusInt OnElementModify(Bentley.DgnPlatformNET.Elements.Element element)
{
return Bentley.DgnPlatformNET.StatusInt.Error;
}
protected override bool OnResetButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
{
ExitTool();
return true;
}
public static void InstallNewInstance()
{
PickAlignmentTool tool = new PickAlignmentTool();
tool.InstallTool();
}
}
}